package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dmortime on 07/03/2014.
 */
public class Customer {
    private List<Book> borrowedBooks = new ArrayList<Book>();
    private String userId;
    private String password;

    Customer(String userId, String password) {
        this.userId = userId;
        this.password = password;
    }

    public List<Book> borrowedBooks() {
        return borrowedBooks;
    }

    public void receiveBook(Book theBook) {
        borrowedBooks.add(theBook);
    }

    public void yieldBook(Book theBook) {
        borrowedBooks.remove(theBook);
    }

    public boolean has(Book theBook) {
        return borrowedBooks.contains(theBook);
    }

    public List<Book> fetchBooksByTitle(String title) {
        List<Book> results = new ArrayList<Book>();
        for(Book book : borrowedBooks()) {
            if(book.getTitle().equals(title)) results.add(book);
        }
        return results;
    }

    public Boolean isCorrectPassword(String password) {
        return password == this.password;
    }

    public String getUserId() {
        return userId;
    }
}
